﻿using System;
using System.Collections.Generic;

using System.Text;
using HZ.Data;
namespace HZ.DrugTrade.DAL
{
    public class DAL_Warning
    {
        public static int AddWarning(IList<HZ.DrugTrade.Model.Warning> list)
        {
            
            var sh = HZ.Data.DbHelperFactory.Create();
            try
            {
                sh.BeginTrans();
                string sql = string.Empty;
                foreach (var item in list)
                {
                    sql = string.Format("SELECT COUNT(1) FROM TB_Warning WHERE OrgID = '{0}' AND WarningType = {1}", item.OrgID, item.WarningType);
                    int i = int.Parse(sh.ExecuteScalar(sql).ToString());
                    if (i == 0)
                    {
                        HZ.Data.DAL_Helper.OperateTableSQL<HZ.DrugTrade.Model.Warning>(item,HZ.Data.TableOperator.Insert,sh);
                    }
                    else
                    {
                        HZ.Data.DAL_Helper.OperateTableSQL<HZ.DrugTrade.Model.Warning>(item, HZ.Data.TableOperator.Update, sh);
                    }
                   
                }
                sh.CommitTrans();
                return 1;

            }
            catch (Exception)
            {
                sh.RollTrans();
                return 0;
            }
        }

        public static int UpadateWarning(IList<HZ.DrugTrade.Model.Warning> list)
        {
            var sh = HZ.Data.DbHelperFactory.Create();
            try
            {
                sh.BeginTrans();
                string sql = string.Empty;
                foreach (var item in list)
                {
                    HZ.Data.DAL_Helper.OperateTableSQL<HZ.DrugTrade.Model.Warning>(item, HZ.Data.TableOperator.Update, sh);
                }
                sh.CommitTrans();
                return 1;

            }
            catch (Exception)
            {
                sh.RollTrans();
                return 0;
            }
        }

        public static IList<HZ.DrugTrade.Model.Warning> GetWarnigSettings(string orgid)
        {
            string sql = string.Format("SELECT * FROM TB_Warning WHERE OrgID = '{0}'", orgid);
           
            return HZ.Data.DAL_Helper.CommonFillList<HZ.DrugTrade.Model.Warning>(HZ.Data.DbHelperFactory.Create().ExecuteTable(sql));
            throw new NotImplementedException();
        }
    }
}
